<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  
  <title>git | ChenBlue | 飞雪连天射白鹿 笑书神侠倚碧鸳</title>

  
  <meta name="author" content="ChenBlue">
  

  
  <meta name="description" content="学习笔记">
  

  
  
  <meta name="keywords" content="git">
  

  <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">

  <meta property="og:title" content="git"/>

  <meta property="og:site_name" content="ChenBlue"/>

  
  <meta property="og:image" content="/blog/favicon.ico"/>
  

  <link href="/blog/favicon.ico" rel="icon">
  <link rel="alternate" href="/blog/atom.xml" title="ChenBlue" type="application/atom+xml">
  <link rel="stylesheet" href="/blog/css/style.css" media="screen" type="text/css">
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
<div class="blog">
  <div class="content">

    <header>
  <div class="site-branding">
    <h1 class="site-title">
      <a href="/blog/">ChenBlue</a>
    </h1>
    <p class="site-description">飞雪连天射白鹿 笑书神侠倚碧鸳</p>
  </div>
  <nav class="site-navigation">
    <ul>
      
    </ul>
  </nav>
</header>

    <main class="site-main posts-loop">
    <article>

  
    
    <h3 class="article-title"><span>git</span></h3>
    
  

  <div class="article-top-meta">
    <span class="posted-on">
      <a href="/blog/2021/07/25/git/" rel="bookmark">
        <time class="entry-date published" datetime="2021-07-25T12:39:03.000Z">
          2021-07-25
        </time>
      </a>
    </span>
  </div>


  

  <div class="article-content">
    <div class="entry">
      
        <h1 id="git-diff打补丁"><a href="#git-diff打补丁" class="headerlink" title="git diff打补丁"></a>git diff打补丁</h1><h3 id="检查patch-diff是否能正常打入"><a href="#检查patch-diff是否能正常打入" class="headerlink" title="检查patch/diff是否能正常打入:"></a>检查patch/diff是否能正常打入:</h3><pre class="language-none"><code class="language-none">git apply --check xxx.patch
git apply --check xxx.diff</code></pre>
<h3 id="打入patch-diff"><a href="#打入patch-diff" class="headerlink" title="打入patch/diff:"></a>打入patch/diff:</h3><pre class="language-none"><code class="language-none">git apply xxx.patch
git apply xxx.diff</code></pre>
<p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/ec04de3f95cc?utm_source=oschina-app">参考文章</a></p>
<h1 id="通过-git-diff-生成-patch-补丁"><a href="#通过-git-diff-生成-patch-补丁" class="headerlink" title="通过 git diff 生成 patch 补丁"></a>通过 git diff 生成 patch 补丁</h1><p><strong>制作两个提交之间的补丁</strong></p>
<p><code>git format-patch 0000000..2222222</code></p>
<p><strong>以未提交的修改为例</strong></p>
<p><code>git diff &gt; 0001.patch</code></p>
<p><strong>但是，如果有新增的文件，并不在 git 管理之内</strong></p>
<p><code>git diff --cached &gt; feature_a.patch</code></p>
<p><strong>如果还包含二进制文件，例如图片等</strong></p>
<p><code>git diff --cached --binary &gt; feature_a.patch</code></p>
<p><strong>应用 patch</strong></p>
<p><code>git apply feature_a.patch</code></p>
<p><strong>生成两个commit之间的补丁</strong></p>
<p><code>git format-patch &lt;base commit id&gt;..&lt;latest commit id&gt;</code></p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/dakewei/p/10518871.html">参考文章</a></p>
<h1 id="分支切换"><a href="#分支切换" class="headerlink" title="分支切换"></a>分支切换</h1><p><strong>创建本地分支并和某个远程分支同步</strong></p>
<p>git checkout -b pamlogic(本地分支) amlogic/p-amlogic(amlogic远程仓库的p-amlogic分支)</p>
<p><strong>查看所有分支</strong><br>git branch -a</p>
<p><strong>删除分支</strong></p>
<p>git branch -D  master</p>
<h1 id="git-commit-默认用nano打开改为用vi打开"><a href="#git-commit-默认用nano打开改为用vi打开" class="headerlink" title="git commit 默认用nano打开改为用vi打开"></a>git commit 默认用nano打开改为用vi打开</h1><p>答:修改~/.gitconfig(修改这个文件将全局有效)或项目目录中的.git/config(修改此文件只是使当前项目默认使用vim)中增加以下内容：</p>
<blockquote>
<p>[core]</p>
<blockquote>
<p>editor=vim</p>
</blockquote>
</blockquote>
<h1 id="git-在原来基础上提交"><a href="#git-在原来基础上提交" class="headerlink" title="git 在原来基础上提交"></a>git 在原来基础上提交</h1><p><code>git commit -a --amend  </code></p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/zndxall/archive/2018/06/21/9207849.html">可以保证change ID不变</a></p>
<h1 id="查看某些修改是那次提交"><a href="#查看某些修改是那次提交" class="headerlink" title="查看某些修改是那次提交"></a>查看某些修改是那次提交</h1><p><code>git blame -L 427,435 FILE</code></p>
<h1 id="git-子模块"><a href="#git-子模块" class="headerlink" title="git 子模块"></a>git 子模块</h1><p><code>git submodule update --init --recursive</code></p>
<h1 id="repo-回退到某个时间点之前"><a href="#repo-回退到某个时间点之前" class="headerlink" title="repo 回退到某个时间点之前"></a>repo 回退到某个时间点之前</h1><pre class="language-none"><code class="language-none">repo forall -c &#39;commitID&#x3D;&#96;git log --before &quot;2019-08-24 07:00&quot; -1 --pretty&#x3D;format:&quot;%H&quot;&#96;; git reset --hard $commitID&#39;</code></pre>
<h1 id="repo-一键导出该仓库的所有修改"><a href="#repo-一键导出该仓库的所有修改" class="headerlink" title="repo 一键导出该仓库的所有修改"></a>repo 一键导出该仓库的所有修改</h1><pre class="language-none"><code class="language-none">repo forall -c git diff &gt; new.diff</code></pre>
      
    </div>

  </div>

  <div class="article-footer">
    <div class="article-meta pull-left">

    
      

    <span class="post-categories">
      <i class="icon-categories"></i>
        <a href="/blog/categories/git/">git</a>
    </span>
    

    
    

    <span class="post-tags">
      <i class="icon-tags"></i>
        <a href="/blog/tags/git/">git</a>
    </span>
    

    </div>

    
  </div>
</article>

  









    </main>

    <footer class="site-footer">
  <p class="site-info">
    Proudly powered by <a href="https://hexo.io/" target="_blank">Hexo</a> and
    Theme by <a href="https://github.com/CodeDaraW/Hacker" target="_blank">Hacker</a>
    </br>
    
    &copy; 2023 ChenBlue
    
  </p>
</footer>
    
    
  </div>
</div>
</body>
</html>